package com.dilidili.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.dilidili.service.SendSms;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service("SenSmsService")
public class SendSmsServiceImpl implements SendSms {
    @Override
    public Map<String,Object> sand(String phoneNum , Map<String,Object> code) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5tAbfe9GYTjUABT3ppn9", "xO8MOh8PkNvOG6QPXNq8hKRt5GX14b");//自己账号的AccessKey信息
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");//短信服务的服务接入地址 官网的不要动
        request.setSysVersion("2017-05-25");//API的版本号 官网的不要动
        request.setSysAction("SendSms");//API的名称 时间的名称
        request.putQueryParameter("PhoneNumbers", phoneNum);//接收短信的手机号码
        request.putQueryParameter("SignName", "可乐童装");//短信签名名称
        request.putQueryParameter("TemplateCode", "SMS_222335329");//短信模板ID
        request.putQueryParameter("TemplateParam", JSONObject.toJSONString(code));//短信模板变量对应的实际值
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
       //     return response.getHttpResponse().isSuccess();
        } catch (ClientException e) {
            e.printStackTrace();
        }
        return null;
    }
}
